package com.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.entity.User;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author zhr
 */
@RestController
public class UserController {
    private static final String DEMO_1_URL = "http://localhost:8080/";
    private final RestTemplate restTemplate;

    public UserController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping("user/list")
    public Page<User> getList(@RequestBody(required = false) Page<User> page) {
        if (page == null) {
            page = new Page<>(1, 10);
        }
//        restTemplate.postForEntity(DEMO_1_URL+"user/list",1,String.class);
        ResponseEntity<Page> forEntity = restTemplate.getForEntity(DEMO_1_URL + "user/list",
                Page.class);
        return forEntity.getBody();
    }
}
